// 注册
$('.regBtn').click(function() {
	getReg()
})

function getReg() {
	$.ajax({
		url: "/nanzhijiamu/php/zhuce.php",
		type: "post",
		data: {
			userName: $("#uName").val(),
			userPwd: $("#uPwd").val(),
		},
		success: function(account) {
			// debugger
			console.log(account);
			if (account == 1) { 
				alert("账号已注册");
			} else {
				alert("注册成功 去登录");
				window.location.href = '/nanzhijiamu/html/denglu.html';
			}

		}
	})
}
// 注册验证
$('#yanzheng').click(function() {
	getYZ()
})
function getYZ() {
	$.ajax({
		url: "/nanzhijiamu/php/yanzheng.php",
		type: "POST",
		data: {
			userName: $("#uName").val(),
		},
		success: function(account) {
			// console.log(yanzheng);
			if (account == "success") {
				alert("用户名已存在");
			} else {
				alert('账号可以注册');
			}

		}
	})
}

//登录
$('.loginBtn').click(function() {
	getLog()
})
function getLog() {
	$.ajax({
		url: "/nanzhijiamu/php/denglu.php",
		type: "POST",
		data: {
			userName: $("#uName").val(),
			userPwd: $("#uPwd").val(),
		},
		success: function(res) {
			// debugger

			console.log(res);
			if (res == "success") {
				alert("登录成功");
				let res = {
					userName: 'qqq',
					id: '1'
				}
				window.location.href = '/nanzhijiamu/html/first.html';
				localStorage.setItem('login', JSON.stringify(res));


			} else {
				alert('账号密码错误或不存在');
			}

		}
	})
}

